<?php
class lang
{
    public static function get($key)
    {
        $key = strtolower($key);
        $words['udnmovies.info'] = array();
        $words['getmovielinks.com'] = array();
        $words['earnmovie.com'] = array();
        $words['moviezfind.com'] = array();
        $words['moviezhunt.com'] = array();
        $words['ttmoviez.com'] = array();
        $words['udnmovies.com'] = array();

        /************* SEO ****************/

        $words['torrentdvdrip.net']['seo_keywords_home'] = '';//'Torrent Download, DVDRip, HD 720p, 1080p, BRRip, HDTV, Bluray, 3D, subs, full movie watch online, AVI, MKV';

        $words['udnmovies.info']['seo_keywords_home'] = '';//'Torrent Download, DVDRip, HD 720p, 1080p, BRRip, HDTV, Bluray, 3D, subs, full movie watch online, AVI, MKV';
        $words['udnmovies.com']['seo_keywords_home'] = 'torrent ????? ????? 2013 - ????? ???? ????? - ?????? ???? ??????';


        $words['torrentdvdrip.net']['seo_keywords_movie'] = '{movie} torrent download, trailer, game, dvdrip, hd 720p, 1080p, brrip, HDTV, Bluray, 3D, subs, dvd rip, xvid, full movie watch online release date AVI, MKV, SoundTrack, Poster, cast, story, review film';
        $words['udnmovies.info']['seo_keywords_movie'] = '{movie}'; //'Torrent download, DVDRip, HD 720p, 1080p, BRRip, HDTV, Bluray, 3D, subs, dvd rip, xvid, full movie watch online, AVI, MKV';
        $words['udnmovies.com']['seo_keywords_movie'] = '{movie} torrent Download Descargar {movie} Descarga ??????? {movie} ????? ?????? {movie} telecharger baixar dvdrip 720p 1080p mkv bluray';

        $words['udnmovies.info']['seo_keywords_person'] = '{person} Movies and Picture Gallery';
        $words['udnmovies.com']['seo_keywords_person'] = '{person} torrent ????? ????? ????? ???';

        $words['torrentdvdrip.net']['seo_description_movie'] = 'Full Movie ' . $words['torrentdvdrip.net']['seo_keywords_movie'] . '. High speed download links for both direct and torrent downloads with subtitles';
        $words['udnmovies.info']['seo_description_movie'] = '{movie}';//'Movie High speed download links for both direct and torrent downloads with subtitles';
        $words['udnmovies.com']['seo_description_movie'] = $words['udnmovies.com']['seo_keywords_movie'] . '????? ????? ?????? ????? ??????? ??? ???? ?? ????? ????? ??????? ????? ?? ??????? ???????'  ;

        $words['torrentdvdrip.net']['seo_url_movie'] = '-torrent-download-watch-online-dvd-dvdrip-brrip-720p-1080p-subs-bluray-3d-full-movie-MKV-xvid-release-date-poster-cast-story-review-film-rapidshare-mediafire-soundtrack';
        $words['udnmovies.info']['seo_url_movie'] = '';//'-Download-dvdrip-brrip-720p-1080p-subs-bluray-3d-full-movie-MKV';
        $words['udnmovies.com']['seo_url_movie'] = '-torrent-download-descargar-{movie}-descarga-???????-{movie}-?????-??????-{movie}-telecharger-baixar-dvd-dvdrip-720p-1080p-bluray-mkv';



        /******************** Movie Page words *********************/
        $words['udnmovies.info']['torrent_download'] = '';//"Torrent Download";
        $words['udnmovies.com']['torrent_download'] = "????? ?????";

        $words['udnmovies.info']['plot'] = "Story";
        $words['udnmovies.com']['plot'] = "?????";

        $words['udnmovies.info']['cast'] = "Cast";
        $words['udnmovies.com']['cast'] = "???? ????????";

        $words['udnmovies.info']['download_seasons'] = "Seasons &amp; Episodes";
        $words['udnmovies.com']['download_seasons'] = "????? ??????? ????????";

        $words['udnmovies.info']['gallery'] = "Photo Gallery";
        $words['udnmovies.com']['gallery'] = "???? ?????";

        $words['udnmovies.info']['similar'] = "Similar Movies";
        $words['udnmovies.com']['similar'] = "????? ??????";

        $words['udnmovies.info']['reviews'] = "User Reviews";
        $words['udnmovies.com']['reviews'] = "??????? ???????";

        $words['udnmovies.info']['find_similar'] = "Find Movies Similar to";
        $words['udnmovies.com']['find_similar'] = "??????? ???????? ??";

        /******************** Person Page words *********************/
        $words['udnmovies.info']['all_person_movies'] = "All Movies for";
        $words['udnmovies.com']['all_person_movies'] = "???? ?????";

        $words['udnmovies.info']['profile'] = "Profile";
        $words['udnmovies.com']['profile'] = "??????";

        $words['udnmovies.info']['cast'] = "Cast";
        $words['udnmovies.com']['cast'] = "???? ????????";

        $words['udnmovies.info']['filmography'] = "Filmography";
        $words['udnmovies.com']['filmography'] = "??????? ??????????";

        /******************** Home Page words *********************/
        $words['udnmovies.info']['home_title'] = "UDNMovies - Your Ultimate Movie Guide";
        $words['udnmovies.com']['home_title'] = "UDNMovies - ????? ?????? ???????";

        $words['udnmovies.info']['home_1'] = "Ever wanted to watch a movie, but did not know what to pick? Then you are in the right place. Welcome to UDNMovies, your ultimate movie guide!";
        $words['udnmovies.info']['home_2'] = "Here you will have access to over 1,000 categorized movies with similar movies, galleries, and more!";
        $words['udnmovies.info']['home_3'] = "Do not forget to like us using the like button at the top right! enjoy searching.";


        $words['udnmovies.com']['home_1'] = "????? ?? ?? UDNMovies? ????? ?????? ????? ??????? ?????? ??????? ?? ???? ???????!";
        $words['udnmovies.com']['home_2'] = "??? ??? ??? ???? ?? 800,000 ???? ??????? ???? ??????  DVDRip, HD 720p, Full HD 1080p ?????? ??????? ???????? ??? ?????? ???????? ??????? ??????!";
        $words['udnmovies.com']['home_3'] = "???? ???????? ?????? ?? ????? uTorrent ?????? ???????. ?????? ?? ?????? ????! ??? ????????! ?????? ?????!";

        $words['udnmovies.info']['home_playing'] = "Now Playing";
        $words['udnmovies.com']['home_playing'] = "???? ?? ???????";

        $words['udnmovies.info']['home_highest'] = "Highest Rated 2013 Movies";
        $words['udnmovies.com']['home_highest'] = "?????? ?????? ?? 2013";

        $words['udnmovies.info']['home_100'] = "Overall Top 100 Movies";
        $words['udnmovies.com']['home_100'] = "?????? ?????? ???????";

		$words['udnmovies.info']['home_popular'] = "Most Popular";
        $words['udnmovies.com']['home_popular'] = "?????? ??????";
		
        $words['udnmovies.info']['home_oscar'] = "Latest Oscar Awards Winners";
        $words['udnmovies.com']['home_oscar'] = "???????? ??? ????? ????????";

        $words['udnmovies.info']['home_bestpic'] = "Latest Best Picture Awards Winners";
        $words['udnmovies.com']['home_bestpic'] = "???????? ??? ????? ???? ????";

        $words['udnmovies.info']['home_golden'] = "Latest Golden Globe Awards Winners";
        $words['udnmovies.com']['home_golden'] = "???????? ??? ????? ????? ????";

        $words['udnmovies.info']['home_emmy'] = "Latest Emmy Awards Winners";
        $words['udnmovies.com']['home_emmy'] = "???????? ??? ????? ????";

        $words['udnmovies.info']['home_soon'] = "Coming Soon";
        $words['udnmovies.com']['home_soon'] = "????? ?? ???????";

        $words['udnmovies.info']['view_more'] = "View More...";
        $words['udnmovies.com']['view_more'] = "?????? ??????...";

        /******************** Download Page words *********************/
        $words['udnmovies.info']['sorry_1'] = "Sorry We Could Not find";
        $words['udnmovies.info']['sorry_2'] = "Do not worry! You can request this movie torrent! we will find it, make it available, and send you an email! Make sure you check back as our torrents are updated daily.";

        $words['udnmovies.com']['sorry_1'] = "????  ???? ???? ????? ??";
        $words['udnmovies.com']['sorry_2'] = "??????! ??????? ??? ??????? ???? ??????! ??? ???? ??? ?????? ?? ?????? ??????? ??? ?? ????? ?? ????? ??? ?????? ??????????! ???? ?? ?????? ?????? ??? ???? ??? ?? ??????? ??? ??????? ??????.";

        $words['udnmovies.info']['email'] = "Your Email:";
        $words['udnmovies.com']['email'] = "????? ??????????:";

        $words['udnmovies.info']['format'] = "Format";
        $words['udnmovies.com']['format'] = "??????";

        /******************** Browse/Search Page words *********************/
        $words['udnmovies.info']['genres'] = "Genres";
        $words['udnmovies.com']['genres'] = "???????";

        $words['udnmovies.info']['search'] = "Search";
        $words['udnmovies.com']['search'] = "???";

        $words['udnmovies.info']['favorites'] = "Add To </br> Favorites";
        $words['udnmovies.com']['favorites'] = "??? ??? </br> ???????";

        $words['udnmovies.info']['tv-series'] = "TV Series";
        $words['udnmovies.info']['action'] = "Action";
        $words['udnmovies.info']['animation'] = "Animation";
        $words['udnmovies.info']['drama'] = "Drama";
        $words['udnmovies.info']['adventure'] = "Adventure";
        $words['udnmovies.info']['biography'] = "Biography";
        $words['udnmovies.info']['comedy'] = "Comedy";
        $words['udnmovies.info']['crime'] = "Crime";
        $words['udnmovies.info']['documentary'] = "Documentary";
        $words['udnmovies.info']['family'] = "Family";
        $words['udnmovies.info']['fantasy'] = "Fantasy";
        $words['udnmovies.info']['film-noir'] = "Film-Noir";
        $words['udnmovies.info']['game-show'] = "Game-Show";
        $words['udnmovies.info']['history'] = "History";
        $words['udnmovies.info']['horror'] = "Horror";
        $words['udnmovies.info']['music'] = "Music";
        $words['udnmovies.info']['musical'] = "Musical";
        $words['udnmovies.info']['mystery'] = "Mystery";
        $words['udnmovies.info']['news'] = "News";
        $words['udnmovies.info']['reality-tv'] = "Reality-TV";
        $words['udnmovies.info']['romance'] = "Romance";
        $words['udnmovies.info']['sci-fi'] = "Sci-Fi";
        $words['udnmovies.info']['sport'] = "Sport";
        $words['udnmovies.info']['talk-show'] = "Talk-Show";
        $words['udnmovies.info']['thriller'] = "Thriller";
        $words['udnmovies.info']['war'] = "War";
        $words['udnmovies.info']['western'] = "Western";

        $words['udnmovies.com']['tv-series'] = "???????";
        $words['udnmovies.com']['action'] = "????";
        $words['udnmovies.com']['animation'] = "???? - ???????";
        $words['udnmovies.com']['drama'] = "?????";
        $words['udnmovies.com']['adventure'] = "??????";
        $words['udnmovies.com']['biography'] = "????";
        $words['udnmovies.com']['comedy'] = "??????";
        $words['udnmovies.com']['crime'] = "?????";
        $words['udnmovies.com']['documentary'] = "??????";
        $words['udnmovies.com']['family'] = "?????";
        $words['udnmovies.com']['fantasy'] = "???????";
        $words['udnmovies.com']['film-noir'] = "????-????";
        $words['udnmovies.com']['game-show'] = "??????";
        $words['udnmovies.com']['history'] = "??????";
        $words['udnmovies.com']['horror'] = "???";
        $words['udnmovies.com']['music'] = "??????";
        $words['udnmovies.com']['musical'] = "??????";
        $words['udnmovies.com']['mystery'] = "????";
        $words['udnmovies.com']['news'] = "?????";
        $words['udnmovies.com']['reality-tv'] = "?????";
        $words['udnmovies.com']['romance'] = "???????";
        $words['udnmovies.com']['sci-fi'] = "???? ????";
        $words['udnmovies.com']['sport'] = "?????";
        $words['udnmovies.com']['talk-show'] = "?????? ??????";
        $words['udnmovies.com']['thriller'] = "?????";
        $words['udnmovies.com']['war'] = "???";
        $words['udnmovies.com']['western'] = "????";

        $domain = str_replace("www.","",$_SERVER['SERVER_NAME']);

        //if($domain == 'localhost')
            $domain = 'udnmovies.info'; //test locally

        //if($domain == 'udnmovies.com')
        //    $domain = "torrentdvdrip.net"; //FORCE ALL TO ENGLISH

        //if($words[$domain][$key] == null)
        //    $domain = 'udnmovies.info'; //all other domains will use trendx if they have no entries



        return $words[$domain][$key];
    }
    public static function translate_jsonp($text)
    {
        $contents = lang::translate($text);
        return 'callback('.$contents.');';
    }
    public static function translate($text)
    {
        /*
                $length = strlen($text);
                $output = '';
                if($length > 500)
                {
                    $pcs = explode('.', $text);
                    $i=0;
                    while($i<count($pcs))
                    {
                        $len = 0;
                        $str='';
                        while($len<500 && $i<count($pcs))
                        {
                            if(strlen($str)+strlen($pcs[$i]) < 500)
                                $str.=$pcs[$i];
                            $i++;
                            $len+=strlen($pcs[$i]);
                        }
                        $output.=lang::get_bing($str);
                    }
                    return $output;
                }
                else*/
        return lang::get_bing($text);
    }
    public static function get_babylon($text)
    {
        //http://translation.babylon.com/translate/babylon.php?v=1.0&q=<TEXT-TO-TRANSLATE>&langpair=0%7C15&callback=babylonTranslator.callback&context=babylon.0.15._babylon_api_response
        $babylon_url = "http://translation.babylon.com/translate/babylon.php?v=1.0&q=".$text."&langpair=0%7C15&callback=babylonTranslator.callback&context=babylon.0.15._babylon_api_response";
        $contents = file_get_contents($babylon_url);
        $open = strpos($contents,'{');
        $close = strpos($contents,'}');
        $length = $close - $open;
        $contents = substr($contents, $open, $length + 1);
        $contents = json_decode($contents,true);
        return $contents['translatedText'];
    }
    public static function get_bing($text)
    {
        try {
            //Client ID of the application.
            $clientID       = "udn";
            //Client Secret key of the application.
            $clientSecret = "z27AAbjIzFi9N5NljmnqN8XVPPyGhdQxbhCrnh51TH4";
            //OAuth Url.
            $authUrl      = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/";
            //Application Scope Url
            $scopeUrl     = "http://api.microsofttranslator.com";
            //Application grant type
            $grantType    = "client_credentials";
            //Create the AccessTokenAuthentication object.
            $authObj      = new AccessTokenAuthentication();
            //Get the Access token.
            $accessToken  = $authObj->getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl);
            //Create the authorization Header string.
            $authHeader = "Authorization: Bearer ". $accessToken;
            //Set the params.//
            $fromLanguage = "en";
            $toLanguage   = "ar";
            $inputStr     = $text;
            $contentType  = 'text/plain';
            $category     = 'general';
            $params = "text=".urlencode($inputStr)."&to=".$toLanguage."&from=".$fromLanguage;
            $translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?$params";
            //Create the Translator Object.
            $translatorObj = new HTTPTranslator();
            //Get the curlResponse.
            $curlResponse = $translatorObj->curlRequest($translateUrl, $authHeader);
            //Interprets a string of XML into an object.
            $xmlObj = simplexml_load_string($curlResponse);
            foreach((array)$xmlObj[0] as $val){
                $translatedStr = $val;
            }
            return $translatedStr;
        } catch (Exception $e) {
            return "Exception: " . $e->getMessage() . PHP_EOL;
        }

    }
    /*
    * Create and execute the HTTP CURL request.
    *
    * @param string $url        HTTP Url.
    * @param string $authHeader Authorization Header string.
    * @param string $postData   Data to post.
    *
    * @return string.
    *
    */
    function curlRequest($url, $authHeader, $postData=''){
        //Initialize the Curl Session.
        $ch = curl_init();
        //Set the Curl url.
        curl_setopt ($ch, CURLOPT_URL, $url);
        //Set the HTTP HEADER Fields.
        curl_setopt ($ch, CURLOPT_HTTPHEADER, array($authHeader,"Content-Type: text/xml"));
        //CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, False);
        if($postData) {
            //Set HTTP POST Request.
            curl_setopt($ch, CURLOPT_POST, TRUE);
            //Set data to POST in HTTP "POST" Operation.
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        }
        //Execute the  cURL session.
        $curlResponse = curl_exec($ch);
        //Get the Error Code returned by Curl.
        $curlErrno = curl_errno($ch);
        if ($curlErrno) {
            $curlError = curl_error($ch);
            throw new Exception($curlError);
        }
        //Close a cURL session.
        curl_close($ch);
        return $curlResponse;
    }
    public static function get_domain_lang()
    {
        $domain = str_replace('www.','',$_SERVER['SERVER_NAME']);

        if($domain == 'localhost') $domain = "udnmovies.info"; //test

        $domains['udnmovies.info'] = "en";
        $domains['trendx.info'] = "en";
        $domains['getmovielinks.com'] = "en";
        $domains['earnmovie.com'] = "en";
        $domains['moviezfind.com'] = "en";
        $domains['moviezhunt.com'] = "en";
        $domains['ttmoviez.com'] = "en";
        $domains['udnmovies.com'] = "ar"; //arabic

        //return $domains[$domain];

        return 'en';
		
		return $domain == 'udnmovies.com' ? 'ar' : 'en';
    }
}
class AccessTokenAuthentication {
    /*
     * Get the access token.
     *
     * @param string $grantType    Grant type.
     * @param string $scopeUrl     Application Scope URL.
     * @param string $clientID     Application client ID.
     * @param string $clientSecret Application client ID.
     * @param string $authUrl      Oauth Url.
     *
     * @return string.
     */
    function getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl){
        try {
            //Initialize the Curl Session.
            $ch = curl_init();
            //Create the request Array.
            $paramArr = array (
                'grant_type'    => $grantType,
                'scope'         => $scopeUrl,
                'client_id'     => $clientID,
                'client_secret' => $clientSecret
            );
            //Create an Http Query.//
            $paramArr = http_build_query($paramArr);
            //Set the Curl URL.
            curl_setopt($ch, CURLOPT_URL, $authUrl);
            //Set HTTP POST Request.
            curl_setopt($ch, CURLOPT_POST, TRUE);
            //Set data to POST in HTTP "POST" Operation.
            curl_setopt($ch, CURLOPT_POSTFIELDS, $paramArr);
            //CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
            //CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            //Execute the  cURL session.
            $strResponse = curl_exec($ch);
            //Get the Error Code returned by Curl.
            $curlErrno = curl_errno($ch);
            if($curlErrno){
                $curlError = curl_error($ch);
                throw new Exception($curlError);
            }
            //Close the Curl Session.
            curl_close($ch);
            //Decode the returned JSON string.
            $objResponse = json_decode($strResponse);
            if ($objResponse->error){
                throw new Exception($objResponse->error_description);
            }
            return $objResponse->access_token;
        } catch (Exception $e) {
            echo "Exception-".$e->getMessage();
        }
    }
}
/*
 * Class:HTTPTranslator
 *
 * Processing the translator request.
 */
Class HTTPTranslator {
    /*
     * Create and execute the HTTP CURL request.
     *
     * @param string $url        HTTP Url.
     * @param string $authHeader Authorization Header string.
     * @param string $postData   Data to post.
     *
     * @return string.
     *
     */
    function curlRequest($url, $authHeader) {
        //Initialize the Curl Session.
        $ch = curl_init();
        //Set the Curl url.
        curl_setopt ($ch, CURLOPT_URL, $url);
        //Set the HTTP HEADER Fields.
        curl_setopt ($ch, CURLOPT_HTTPHEADER, array($authHeader,"Content-Type: text/xml"));
        //CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, False);
        //Execute the  cURL session.
        $curlResponse = curl_exec($ch);
        //Get the Error Code returned by Curl.
        $curlErrno = curl_errno($ch);
        if ($curlErrno) {
            $curlError = curl_error($ch);
            throw new Exception($curlError);
        }
        //Close a cURL session.
        curl_close($ch);
        return $curlResponse;
    }
}

